#ifndef CHARACTER_H
#define CHARACTER_H

#include <iconv.h>

static inline int UTF82GB2312(char **utf8, size_t *s, char **gb2312, size_t *rs)
{
	int ret;
	iconv_t cvt = iconv_open("GB2312", "UTF-8");
	if ((iconv_t) -1 == cvt) {
		perror("iconv_open");
		return -1;
	}
	ret = (int) iconv(cvt, utf8, s, gb2312, rs);
	if (ret == -1) {
		perror("iconv");
	}
	iconv_close(cvt);
	return ret;
}

#endif /* CHARACTER_H */
